package com;
import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.util.List;
/**
 * Created by webrx on 2018-01-15.
 */
public class Demo {
    @Test
    public void mm() throws IOException {
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
        SqlSession session = sf.openSession();
        BookMapper bdao = session.getMapper(BookMapper.class);
        //插入一本书籍
        bdao.insert("《java2018入门》");
        session.commit();
        //查询书籍信息
        List<Book> books = bdao.query();
        for(Book book : books){
            System.out.println(book.getId());
            System.out.println(book.getName());
        }
    }
}
